import {
    ListExpBarActionType,
    ICtrlEvent,
    IListExpBarAbility,
    IListExpBarControllerParams,
    IListExpBarModel,
    IListExpBarStore,
    IParam,
    IListExpBarController,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
    getExpBarClassNames,
    handleCtrlAction,
    handleCtrlDestroy,
    handleCtrlInit,
    handleQuickSearch,
    handleToolbarItemClick,
    useCtrlAction,
    useCtrlBasic,
    useCtrlControllerParams,
    useCtrlProps,
} from '../use-ctrl';

/**
 * 表格导航输入参数
 *
 * @export
 * @return {*}
 */
export function useListExpBarProps() {
    return {
        ...useCtrlProps(),
        openView: Function,
        newView: Function,
    };
}

/**
 * 表格导航基础参数
 *
 * @export
 * @param {IListExpBarModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useListExpBarBasic(model: IListExpBarModel, props: IParam) {
    const getClassNames = (props: IParam) => {
        const names = getExpBarClassNames(model, props);
        return names;
    };
    return {
        ...useCtrlBasic(model, props),
        getClassNames,
        handleToolbarItemClick,
        handleQuickSearch,
        handleCtrlDestroy,
        handleCtrlInit, 
        handleCtrlAction,
    };
}

/**
 * 表格导航部件行为
 *
 * @export
 */
export function useListExpBarAction(controller: IListExpBarController<IListExpBarStore,IListExpBarAbility>) {
    return {
        ...useCtrlAction(controller),
    };
}

/**
 * 表格导航部件控制器
 *
 * @export
 */
export function useListExpBarControllerParams<
    S extends IListExpBarStore,
    M extends IListExpBarModel
>(
    model: M,
    props: any,
    evt: QXEvent<ICtrlEvent<ListExpBarActionType, IListExpBarAbility>>,
    otherParams: IParam = {},
): IListExpBarControllerParams<ListExpBarActionType, IListExpBarAbility> {
    return {
        ...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
        openView: props.openView,
        newView: props.newView,
    };
}
